        var osellListStore = new Ext.data.JsonStore({
			url: '/weihe/getList_sellList',
			root: 'datas',
			fields : [{
						name:'OsellId',mapping:'id'
					},{
     				   name:'OsellDate', mapping:'date',type : 'date', dateFormat:"Y-m-d"
      			  	},{
						name:'OsellRunway',mapping:'runway'
					},{
						name:'OsellCompany',mapping:'company'
					},{
						name:'OsellProject',mapping:'project'
				    },{
				    	name:'OsellCount',mapping:'count'
				    },{
				    	name:'OsellPayment',mapping:'payment'
				    },{
				    	name:'OsellMoney',mapping:'money'
				    },{
						name:'OsellAmount',mapping:'sellSum', convert:function(v){ 
														return v ? v.amount : undefined;}
			        },{
						name:'OsellTotal',mapping:'sellSum', convert:function(v){ 
														return v ? v.total : undefined;}
			          }],
				    baseParams : {'sellList.type': 'oversea'}
		});
    	
    	
osellLists = function(){
	var tmp="";
	
  return{
     
	  osellListGrid : function(){

		var pageToolBar = new Ext.PagingToolbar({
			pageSize : 15,
			store : osellListStore,
			displayInfo : true,
			displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
		    emptyMsg : "没有记录显示!",
		    firstText : '首页',
		    prevText : '上一页',
		    nextText : '下一页',
		    lastText : '尾页',
		    beforePageText : '第',
		    afterPageText : '页,共{0}页'
		});

	

		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
		 
	   var osellListGrid = new Ext.grid.GridPanel({
		   id:'osellListGrid',
		   title : '国外(美金)',
		   region : 'center',
		   minColumnWidth : 50,
		   tbar:["-",{
	   						text:"输入查询条件",
								handler:function(){
										osellLists.infoWin().show();
								}
	   					},"-"],

		   loadMask : {msg:'正在加载数据，请稍侯...'},
		   store : osellListStore,
		   columns: [
		             {header : '单位名称', dataIndex : 'OsellCompany'},
		             {header : '经营方式', dataIndex : 'OsellRunway'},
		             {header : '项目', dataIndex : 'OsellProject'},
		             {header : '结算方式', dataIndex : 'OsellPayment'},
		             {header : '当日数量', dataIndex : 'OsellCount', menuDisabled : true,renderer:function(value){
							if(value != 0){
									return value;
								}else{
									return '';
								}
		             }},
		              {header : '当日金额', dataIndex : 'OsellMoney', menuDisabled : true,renderer:function(value){
							if(value != 0){
									return value;
								}else{
									return '';
								}
		             }},
		             {header : '累计数量', dataIndex : 'OsellAmount'},
		             {header : '累计金额', dataIndex : 'OsellTotal'}
        ],
           sm : rowSelectionModel,
           listeners :{ 
			   'rowclick':function(grid, rowIndex, event) {
			   var record = grid.getStore().getAt(rowIndex);
			   	   tmp = record.id;
			   	   var kk = record.get('OsellRunway');
			   	   if(kk == '小计' || kk == '本月合计'){
			   	   		Ext.Msg.alert('提示','合计数据不能修改!');
			   	   }else{
				  	 	Ext.getCmp("osellListForm").form.loadRecord(record);
				 	 	Ext.getCmp("osellListForm").buttons[0].setText('修改');
			   	   }
			   }
		   
		},
		  viewConfig : {
		     forceFit : false
		  },
		  bbar : pageToolBar
});
		return osellListGrid;
	},
	
	
	infoWin : function(){
  	  var infoWin = new Ext.Window({
  	  	id: 'osellInfo',
        title:'销售明细查询',
        layout: 'fit',
        width:330,    
        height:250,
        modal: true,
        draggable : false,
        resizable: false,
        closeAction:"close",
        plain:true,    
        items:[osellLists.queryForm()] 
        
    });  
  		return infoWin;
  	},
  	
  	queryForm : function(){
  		
	
	   var wayComboData = new Ext.data.SimpleStore({
		  fields : ['text'],
		  data : [['批发'],['零售'],['代理']]
	  });
  		
  	 var queryForm = new Ext.form.FormPanel({
			baseCls:"x-plain",
			frame : true,
			autoHeight : true,
			labelAlign : 'right',
			labelWidth : 85,
			defaultType : 'textfield',
				defaults : {
				width : 200
			},
			items : [{
					  fieldLabel: "单位名称",
      	    		  name: "sellList.company"
			 	  },{
					  fieldLabel : '经营方式',
 					  name : 'sellList.runway',
 					  xtype : 'combo',
 					  store : wayComboData,
 					  emptyText : '请选择',
 				      mode : 'local',
 					  triggerAction : 'all',
 					  editable: false,
 					  displayField : 'text',
 					  value : '批发'
				   },{
					  fieldLabel: "项目",
      	    		  name: "sellList.project"
			 	  },{
            		  xtype: 'datefield',
                      fieldLabel: "日期",
                      format : 'Y-m-d',
            		  name: "sellList.date",
            		  value : (new Date()).format('Y-m-d')
				   }],
			buttons:[{
        		 text:'确认',
             	 handler:function(){
             	 	var company = queryForm.form.findField('sellList.company').getValue()
             	 	var runway = queryForm.form.findField('sellList.runway').getValue()
             	 	var project = queryForm.form.findField('sellList.project').getValue()
             	 	var date = queryForm.form.findField('sellList.date').getValue();
				 Ext.getCmp("osellListGrid").getStore().baseParams = {'flag': true,'sellList.company':company,
					 													  'sellList.project':project,
					 													  'sellList.runway':runway,
					 													  'sellList.date':date,
					 													  'sellList.type':'oversea'};
				 Ext.getCmp("osellListGrid").getStore().load({params : {start : 0, limit : 15}});
				 queryForm.form.reset();
                 Ext.getCmp("osellInfo").close();
              	
              	}
              },{
                 text:'取消',
                 handler:function(){
                 	queryForm.form.reset();
                 	Ext.getCmp("osellInfo").close();
                 }
              }]   
        });
        return queryForm;
  	
  	},
	osellListForm : function(){
		var button_add = new Ext.Button({
			text : '添加',
			handler : function() {
					progressConsole();
				if(osellListForm.form.isValid()){ 	
					if (osellListForm.form.findField("sellList.id").getValue() == "") {
						osellListForm.form.submit({
						  url : '/weihe/add_sellList',
						   success : function(form, action) {
							 if (action.result.success) {
								Ext.Msg.alert('消息', action.result.msg, function() {
									   osellListForm.form.reset();
									   Ext.getCmp("osellListGrid").getStore().reload();
								});
							  }
						    }
					    });
					}else {
						osellListForm.form.submit({
							  url : '/weihe/update_sellList',
							   success : function(form, action) {
								 if (action.result.success) {
									Ext.Msg.alert('消息', action.result.msg, function() {
										osellListForm.form.reset();
										Ext.getCmp("osellListGrid").getStore().reload();
										osellListForm.buttons[0].setText('添加');
										
									});
								  }
							    }
						    });
					}
			}else{
				Ext.Msg.alert('提示','请输入相关内容');
			}
				}
		
			
		});

	var button_clear = new Ext.Button({
		id : 'button_clear',
		text : '清空',
		handler : function() {
			osellListForm.form.reset();
			osellListForm.buttons[0].setText('添加');
		}
	});

	var button_del = new Ext.Button({
		text : '删除',
		handler : function() {
			var id = osellListForm.form.findField('sellList.id').getValue();
			if (id == '') {
				Ext.Msg.alert('提示', '请选择需要删除的信息!');
			} else {
				progressConsole();
				Ext.Ajax.request({
					url : '/weihe/delete_sellList',
					success : function(response) {
						var json = Ext.decode(response.responseText);
						if (json.success) {
							Ext.Msg.alert('消息', json.msg, function() {
								Ext.getCmp("osellListGrid").getStore().load({params : {start : 0, limit : 15}});
								osellListForm.form.reset();
								osellListForm.buttons[0].setText('添加');
							});
						}else{
							Ext.Msg.alert('消息', json.msg);
							osellListForm.form.reset();
							osellListForm.buttons[0].setText('添加');
						}
					},
					failure : function() {
						Ext.Msg.alert('错误', '删除失败!');
					},
					params : 'sellList.id=' + id
				});
			}
		}
	});
	

	  var wayComboData = new Ext.data.SimpleStore({
		  fields : ['text'],
		  data : [['批发'],['零售'],['代理']]
	  });

	var  osellListForm = new Ext.form.FormPanel({
		id : 'osellListForm',
		title : '销售明细信息',
		frame : true,
		width : 300,
		region : 'east',
		autoScroll : true,
		labelAlign : 'right',
		labelWidth : 60,
		defaultType : 'textfield',
			defaults : {
			width : 200
		},
		items : [{  
			id:'OsellId',
			xtype : 'hidden',  
			name : 'sellList.id'
		},{  
			id:'OsellType',
			xtype : 'hidden',  
			name : 'sellList.type',
			value: 'oversea'
		},{
			id:'OsellCompany',
			fieldLabel : '单位名称',
			name : 'sellList.company'
		},{
			id:'OsellRunway',
			fieldLabel : '经营方式',
 			name : 'sellList.runway',
 			xtype : 'combo',
 			store : wayComboData,
 			emptyText : '请选择',
 			mode : 'local',
 			triggerAction : 'all',
 			allowBlank:false,
 			editable: false,
 			displayField : 'text'
		},{
			id:'OsellProject',
			fieldLabel : '项目',
			name : 'sellList.project'
		},{
			id:'OsellPayment',
			fieldLabel : '结算方式',
			name : 'sellList.payment'
		},{
			id: 'OsellDate',
            xtype: 'datefield',
            fieldLabel: "发生时间", 
            format : 'Y-m-d',
    	    allowBlank:false,
            name: "sellList.date",
            value : (new Date()).format('Y-m-d')
		},{
			id:'OsellCount',
			fieldLabel : '数量',
			name : 'sellList.count',
			regex : /^[1-9]\d*$/,
		    regexText:'请输入有效的数量'  
		},{
			id:'OsellMoney',
			fieldLabel : '金额',
			name : 'sellList.money',
			regex : /^\d+(\.\d+)?$/,
		    regexText:'请输入有效的价格' 
		}],
		buttons : [button_add,button_clear,button_del]
	});
		return  osellListForm;
	}
  }
}();








